package com.ash.controller.book;

import com.ash.service.book.BookTypeService;
import com.ash.service.type.TypeService;
import com.ash.util.JsonUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/3/25 16:26
 * @file : project06.com.ash.controller.book.BookTypeController.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
@Controller
public class BookTypeController {
    @Resource
    BookTypeService bookTypeService;
    @Resource
    TypeService typeService;
    @RequestMapping("/user/bookType/type")
    public String type(Model model, @RequestParam("bid")Integer bid){
        System.out.println(bid+"===============");
        System.out.println(bookTypeService.selectTypeByBid(bid));
         model.addAttribute("bookType", JsonUtil.getJsonByObject(bookTypeService.selectTypeByBid(bid)));
         model.addAttribute("types",JsonUtil.getJsonByObject(typeService.selectAll(null,null)));
         model.addAttribute("bid",JsonUtil.getJsonByObject(bid));
         return "user/bookType";
    }
    @PostMapping("/user/bookType/type")
    @ResponseBody
    public Integer types(@RequestParam("bid")Integer bid,@RequestParam("bookTypes")List<Integer> bookTypes){
        return bookTypeService.changeType(bid,bookTypes);
    }

}
